#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'libb@anchent.com'

import pickle
# dump和dumps是序列化，load和loads是反序列化
dict1 = {'a': 1, 'b': 2}
dict2 = pickle.dumps(dict1)
print(dict2, type(dict1), type(dict2), id(dict1), id(dict2))

dict3 = pickle.loads(dict2)
print(dict3, type(dict3), id(dict1), id(dict2), id(dict3))

# dump 和 load 是序列化和反序列化到文件中
file1 = open('../assets/004.jpg', 'wb')
file2 = pickle.dump(dict1, file1)
print(file2, type(file2))
file1.close()

file3 = open('../assets/004.jpg', 'rb')
file4 = pickle.load(file3)
print(file4, type(file4))
file3.close()